package com.work.keep.adapter;

import android.content.Context;
import android.content.DialogInterface;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.work.keep.R;
import com.work.keep.activity.OnRecyclerItemClickListener;

/**
 * Created by dllo on 16/1/21.
 */
public class UserInforAdapter extends RecyclerView.Adapter {
    private Context context;
    private String text[] = {"训练等级", "我的徽章", "我的收藏", "个人资料"};
    private String text1[] = {"动态", "关注", "粉丝"};
    private int drawer[] = {R.mipmap.grade, R.mipmap.badge, R.mipmap.star, R.mipmap.personal};
    private View.OnClickListener onClickListener;
    public UserInforAdapter(Context context) {
        this.context = context;
    }

    private OnRecyclerItemClickListener onRecyclerItemClickListener;

    public void setOnRecyclerItemClickListener(OnRecyclerItemClickListener onRecyclerItemClickListener) {
        this.onRecyclerItemClickListener = onRecyclerItemClickListener;
    }

    @Override
    public int getItemViewType(int position) {
        return position;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v;
        if (viewType == 0) {
            v = LayoutInflater.from(context).inflate(R.layout.item_userinfor_one, parent, false);
            UserInforViewHolderOne holderOne = new UserInforViewHolderOne(v);
            return holderOne;
        }
        if (viewType == 1 || viewType == 2 || viewType == 3) {
            v = LayoutInflater.from(context).inflate(R.layout.item_userinfor_two, parent, false);
            UserInforViewHolderTwo holderTwo = new UserInforViewHolderTwo(v);
            return holderTwo;
        }
        v = LayoutInflater.from(context).inflate(R.layout.item_userinfor_three, parent, false);
        UserInforViewHolderThree holderTwo = new UserInforViewHolderThree(v);
        return holderTwo;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        if (position == 0) {
            UserInforViewHolderOne holderOne = ((UserInforViewHolderOne) holder);
//            holderOne.userInforAvater
//        holderOne.userInforName.setText();
        }
        if (position > 0 && position <= 3) {
            UserInforViewHolderTwo holderTwo = ((UserInforViewHolderTwo) holder);
            holderTwo.dynamicText.setText(text1[position - 1]);
        }
        if (position > 3) {
            UserInforViewHolderThree holderThree = ((UserInforViewHolderThree) holder);
            holderThree.userInforTwoText.setText(text[position - 4]);
            holderThree.userInforTwoIcon.setImageResource(drawer[position - 4]);

            holderThree.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    if (onRecyclerItemClickListener != null) {
                        onRecyclerItemClickListener.onItemClick(position - 4);
                    }
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return text.length + 4;
    }

    class UserInforViewHolderOne extends RecyclerView.ViewHolder {
        ImageView userInforAvater;
        TextView userInforName;

        public UserInforViewHolderOne(View itemView) {
            super(itemView);
            userInforAvater = (ImageView) itemView.findViewById(R.id.userInforAvater);
            userInforName = (TextView) itemView.findViewById(R.id.userInforName);
        }
    }

    class UserInforViewHolderTwo extends RecyclerView.ViewHolder {
        TextView dynamicText, userInforDynamicCount;

        public UserInforViewHolderTwo(View itemView) {
            super(itemView);
            dynamicText = (TextView) itemView.findViewById(R.id.dynamicText);
            userInforDynamicCount = (TextView) itemView.findViewById(R.id.userInforDynamicCount);
        }
    }

    class UserInforViewHolderThree extends RecyclerView.ViewHolder {
        TextView userInforTwoText;
        ImageView userInforTwoIcon;

        public UserInforViewHolderThree(View itemView) {
            super(itemView);
            userInforTwoText = (TextView) itemView.findViewById(R.id.userInforTwoText);
            userInforTwoIcon = (ImageView) itemView.findViewById(R.id.userInforTwoIcon);
        }
    }

}
